use axum::http::StatusCode;
use axum::response::{IntoResponse, Response};
use axum::Json;
use serde::Deserialize;
use validator::Validate;

#[derive(Debug, Deserialize, Validate)]
pub struct RequestUser {
    #[validate(length(
        min = 3,
        max = 8,
        message = "Username must be between 3 and 8 characters"
    ))]
    pub username: String,
    #[validate(length(min = 3, message = "Password must be at least 3 characters long"))]
    pub password: String,
}
pub async fn custom_json_extractor(Json(user): Json<RequestUser>) -> Response {
    if let Err(err) = user.validate() {
        return (StatusCode::BAD_REQUEST, err.to_string()).into_response();
        // return (StatusCode::BAD_REQUEST, err.to_string())
    }
    (
        StatusCode::OK,
        format!("Username: {}, Password: {}", user.username, user.password),
    )
        .into_response()
}
